app.controller('integralSearchCtrl', function($scope, $stateParams, $http,$ionicLoading) {
    var currentPageNum = 1;
    var totalCountNum = 0;
    var pageOrder = null;
    //用户数据
    var user_info = JSON.parse(localStorage.getItem("UserInfo"));
    // var getPath = JSON.parse(localStorage.getItem("getPath"));
    angular.element(document).ready(function(){
        $scope.getintegralList();
    })

    //获取成绩列表
    $scope.getintegralList = function () {
        var url = getPath.url+getPath.name+"/app/findScoreList";
        $http({
            url: url,
            method: "POST",
            headers:{'Content-Type':'application/x-www-form-urlencoded'},
            data: {
                userId:user_info.userId ,
                currentPage:currentPageNum,
                pageSize:7
            }
        }).success(function (data) {
                $scope.nScoreDetailSum = data.resultBean.nScoreDetailSum;
                $scope.integralList = data.resultBean.pageResult.resultList;

                //计算总页数
                totalPage=data.resultBean.pageResult.pageCond;
                totalCountNum =  (totalPage.totalCount%totalPage.pageSize==0)?totalPage.totalCount/totalPage.pageSize:parseInt(totalPage.totalCount/totalPage.pageSize)+1;
                $scope.totalCount = totalCountNum;

                $scope.currentPage = totalPage.currentPage;
            })
            .error(function () {
                $ionicLoading.show({
                    template: "获取数据失败，请联系管理员!",
                    duration: 3000
                });
            });
    }

    //切换页面
    $scope.changeIntegralPage = function (pageOrderName) {
        pageOrder = pageOrderName;
        if(pageOrder == 'previous'){
           if(--currentPageNum>0){
               $scope.getintegralList();
           }else{
               currentPageNum++;
           }
        }else if (pageOrder == 'follow'){
            if(++currentPageNum<=totalCountNum){
                $scope.getintegralList();
            }else{
                currentPageNum--;
            }
        }
    }

})